import { getToken } from '@/utils/cookie'
import router from './router'
import store from './store'
import Nprogress from 'nprogress'
import 'nprogress/nprogress.css'
router.beforeEach((to, from, next) => {
  Nprogress.start()
  if (getToken()) {
    if (to.path === '/login/true') {
      next({ path: '/' })
      Nprogress.done()
    } else {
      store.dispatch('GetUserInfo').then(res => {
        next()
      })
    }
  } else {
    if (to.path !== '/login/true') {
      next('/login/true')
    } else {
      next()
    }
    Nprogress.done()
  }
})
router.afterEach(() => {
  Nprogress.done() // 结束Progress
})
